/*
+ --------------------------------------------------- +
|  Ineo Article Manager - Version 2.x
|  Copyright 2006-2007, Dan Cryer and William McGann
+ --------------------------------------------------- +

Ineo Article Manager is free software; you can redistribute it and/or modify
it under the terms of version 3 of the GNU General Public License as published by
the Free Software Foundation.

Ineo Article Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Ineo; see the file License.txt.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

*/

var ineoAjaxUrl           = 'index.php?autocom=ineo&mod=dynamic&';	
var ineoAjaxRequestType   = 'GET';
var ineoAjaxPostData      = '';
var ineoAjaxRequest       = new ajax_request();
var ineoAjaxCache         = new Array();

ineoAjaxRequest.xml_init();

/**
* Standard Ineo AJAX call, replaces returned content into an area defined by it's ID.
*/
function ineoAjaxReplace( urlParams , contentAreaId , loadingMessage )
{
	if( ineoAjaxIsCached(urlParams) )
	{
		return ineoAjaxCacheReplace(contentAreaId,urlParams);
	}
	
	if( loadingMessage != null )
	{
		ineoAjaxRequest.show_loading( loadingMessage );
	}
	
	var myEvent = function()
	{
		if( ineoAjaxRequest.readystate_ready_and_ok() )
		{
			// Set cache:
			ineoAjaxSetCache(urlParams,ineoAjaxRequest.xmlhandler.responseText);
			// Do Replace
			ineoAjaxReplaceEvent( contentAreaId , ineoAjaxRequest.xmlhandler.responseText )
		}
	}
	
	ineoAjaxRequest.onreadystatechange( myEvent );
	
	ineoAjaxRequest.process( ineoAjaxUrl + urlParams , ineoAjaxRequestType , ineoAjaxPostData );
}

/**
* Ineo AJAX Call With Event Handler
*/
function ineoAjaxEvent( urlParams , eventHandler , loadingMessage )
{
	if( loadingMessage != null )
	{
		ineoAjaxRequest.show_loading( loadingMessage );
	}
	
	ineoAjaxRequest.onreadystatechange( eventHandler );
	
	ineoAjaxRequest.process( ineoAjaxUrl + urlParams , ineoAjaxRequestType , ineoAjaxPostData );
}

/**
* ineoAjaxReplace event handler
*/
function ineoAjaxReplaceEvent( contentArea , newContent )
{
	// Hide our loading message:
	ineoAjaxRequest.hide_loading();
	
	// Get and show the content area:
	var dyn = document.getElementById(contentArea);
	dyn.style.display = '';
		
	// Replace content into the area:
	dyn.innerHTML = newContent;
		
	return true;
}

/**
* Get ajax request response text
*/
function ineoAjaxResponseText()
{
	return ineoAjaxRequest.xmlhandler.responseText;
}

/**
* Ajax ready and ok state?
*/
function ineoAjaxReady()
{
	return ineoAjaxRequest.readystate_ready_and_ok();
}

/**
* Is this Ajax request already cached?
*/
function ineoAjaxIsCached( func_id )
{
	if( !ineoAjaxCache[func_id] )
	{
		return false;
	}
	else
	{
		return true;
	}
}

/**
* Set To Cache:
*/
function ineoAjaxSetCache( urlparams, content )
{
	ineoAjaxCache[urlparams] = content;
}

/**
* Get From Cache:
*/
function ineoAjaxGetCache( urlparams )
{
	return ineoAjaxCache[urlparams];
}

/**
* Do "Replace Event" using cache
*/
function ineoAjaxCacheReplace( contentarea, urlParams )
{
	document.getElementById(contentarea).innerHTML = ineoAjaxGetCache(urlParams);
}
